package com.ctsi.ssdc.controller;

import com.ctsi.ssdc.entity.Excel11;
import com.ctsi.ssdc.entity.FixedInvestment;
import com.ctsi.ssdc.service.Excel11Service;
import com.ctsi.ssdc.service.ExcelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 11基础表投资（工投基础）(Excel11)表控制层
 *
 * @author makejava
 * @since 2023-02-21 19:48:06
 */
@RestController
@RequestMapping("excel/11")
public class Excel11Controller {
    /**
     * 服务对象
     */
    @Resource
    private Excel11Service excel11Service;
    @Resource
    private ExcelService excelService;

    /**
     * 分页查询
     *
     * @param excel11 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Excel11>> queryByPage(Excel11 excel11,@PageableDefault Pageable pageRequest) {
        return ResponseEntity.ok(this.excel11Service.queryByPage(excel11,(PageRequest) pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Excel11> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.excel11Service.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param excel11 实体
     * @return 新增结果
     */
    @PostMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel11> add(Excel11 excel11) {
        Excel11 insert = this.excel11Service.insert(excel11);
        excelService.sheet11Cal(excel11.getStatisticalTime());
        return ResponseEntity.ok(insert);
    }

    /**
     * 编辑数据
     *
     * @param excel11 实体
     * @return 编辑结果
     */
    @PutMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel11> edit(Excel11 excel11) {
        Excel11 update = this.excel11Service.update(excel11);
        excelService.sheet11Cal(excel11.getStatisticalTime());
        return ResponseEntity.ok(update);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Boolean> deleteById(Long id) {
        Excel11 excel11 = excel11Service.queryById(id);
        boolean res = this.excel11Service.deleteById(id);
        excelService.sheet11Cal(excel11.getStatisticalTime());
        return ResponseEntity.ok(res);
    }

    /**
     * 获取工业投资当月 + 累计 + 累计同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取工业投资当月 + 累计 + 累计同比")
    @GetMapping("industrialInvestmentInfo/{year}/{month}")
    public ResponseEntity<FixedInvestment> getIndustrialInvestmentInfo(@PathVariable("year") String year,
                                                                       @PathVariable("month") String month) {
        return ResponseEntity.ok(excel11Service.getIndustrialInvestmentInfo(year,month));
    }

    /**
     * 获取基础设施项目投资当月 + 累计 + 累计同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("基础设施项目投资当月 + 累计 + 累计同比")
    @GetMapping("basicInvestmentInfo/{year}/{month}")
    public ResponseEntity<FixedInvestment> getBasicInvestmentInfo(@PathVariable("year") String year,
                                                                          @PathVariable("month") String month) {
        return ResponseEntity.ok(excel11Service.getBasicInvestmentInfo(year,month));
    }

    /**
     * 全社会固定资产投资当月 + 累计 + 累计同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("全社会固定资产投资当月 + 累计 + 累计同比")
    @GetMapping("socialFixedInvestmentInfo/{year}/{month}")
    public ResponseEntity<FixedInvestment> getSocialFixedInvestmentInfo(@PathVariable("year") String year,
                                                                                      @PathVariable("month") String month) {
        return ResponseEntity.ok(excel11Service.getSocialFixedInvestmentInfo(year,month));
    }

}

